<?php
    $url = new Url();
    $arr_bann = LoadConfig::$bann;
    $current_url = Common::getCurrentUrl();
    $path_paging = strpos($current_url,'?') !==false ? $current_url.'&' : $current_url.'?';
    $path_paging = str_replace("?page=".$page."&","?",$path_paging);
    $path_paging = str_replace("&page=".$page."&","&",$path_paging);
?>
<script type="text/javascript">
    function ajaxQuickUpdate(id){

        var strUrl = "<?php echo $url->createUrl("bannchat/ajaxQuickUpdate") ?>";
        if(confirm('Bạn có chắc chắn muốn bỏ bann không ?')){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id,
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Bỏ bann thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <form method="GET">
            <ul class="form4">
                <li class="clearfix"><label><strong>Username </strong>:</label>
                    <div class="filltext">
                        <input type="text" style="width:196px;margin-right:28px" value="<?php echo $username?>" name="username">
                    </div>
                </li>
                <li class="clearfix"><label><strong>Trạng thái</strong>:</label>
                    <div class="filltext">
                        <select style="width:203px;" name="bann">
                            <option value="2" >- Tất cả -</option> 
                            <?php foreach($arr_bann as $key=>$value){?>
                                <option value="<?php echo $key;?>" <?php echo ($bann == $key ? 'selected="selected"':'' )?>><?php echo $value?></option>
                                <?php }?>
                        </select>
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input type="submit" value=" Tìm kiếm" class="btn-bigblue"> 
                    </div>
                </li>

            </ul>
        </form> 
    </div>
    <div class="box">

        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">
                        <td width="4%"><strong>ID</strong></td>
                        <td width="25%"><strong>Username</strong></td>
                        <td width="30%"><strong>Thời gian</strong></td>
                        <td width="15%"><strong>Trạng thái</strong></td>
                        <td width="20%"><strong>Hành động</strong></td>
                    </tr>
                    <?php foreach($data as $key=>$value){?>
                        <tr>
                            <td><?php echo $value["id"];?></td>  
                            <td><?php echo $value["username"];?></td>  
                            <td>
                                <?php 
                                    if($value['bann_chat']==1){
                                        echo date('d/m/Y',$value["from_date"])."&nbsp &nbsp &nbsp - &nbsp &nbsp &nbsp   ".date('d/m/Y',$value["to_date"]);
                                    }
                                    else{
                                        echo "";
                                    }
                                ?>
                            </td>  

                            <td>
                                <?php 
                                    if($value['bann_chat']==0){
                                        echo " ";
                                    } else{
                                        echo "Bị Bann";
                                    }
                                ?> 
                            </td>
                            <td>
                                <a href="<?php echo $url->createUrl("bannchat/add",array("id"=>$value["id"],"username"=>$value['username']))?>"> Ban </a> |
                                <a class="s14" href="javascript:void(0)" onclick="ajaxQuickUpdate('<?php echo $value["id"]?>')"> Bỏ Ban </a> 

                            </td>
                        </tr>
                        <?php }?>
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                    <?php  
                        echo Paging::show_paging_cp($max_page,$page,$path_paging);
                    ?>
                </ul>
            </div>
        </div>
    </div>
</div>